package com.example.demo.service.impl;

import com.example.demo.common.ResponseMessage;
import com.example.demo.dao.GoodsMapper;
import com.example.demo.pojo.Goods;
import com.example.demo.service.IGoodService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("iProductService")
public class GoodServiceImpl implements IGoodService {
    @Autowired
    private GoodsMapper goodsMapper;
    @Override
    public ResponseMessage getGoodsList(String keyword,int categoryId,int nowPage, int pageSize) {
        //分页插件
        PageHelper.startPage(nowPage,pageSize);
        List<Goods> productList = goodsMapper.selectAllByPage(categoryId,keyword);
        PageInfo pageInfo = new PageInfo(productList);
        return ResponseMessage.createSuccessMessage(pageInfo);
    }
    @Override
    public ResponseMessage getGoodDetail(int productId){
        Goods productDetail = goodsMapper.selectByPrimaryKey(productId);
        return ResponseMessage.createSuccessMessage(productDetail);
    }
}
